﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Media;
using System.Drawing;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Shapes;
namespace HA.Data
{
    [Serializable]
   public class DOModFlow:ICloneable
   {

       #region 构造函数

        public DOModFlow()
        {
           
            this._wells = new DOEntity(Color.Gold, DisplayShape.Diamond);           
            this._drains = new DOEntity(Color.Blue, DisplayShape.Diamond);
            this._rivers = new DOEntity(Color.Blue, DisplayShape.TriangleUp);          
            this._constantHead = new DOEntity(Color.Black, DisplayShape.Diamond);
            this._generalHead = new DOEntity(Color.Green, DisplayShape.TriangleUp);
            this._transientData = new DOEntity(Color.Purple, DisplayShape.Diamond);
            this._dryCell = new DOEntity(Color.Red, DisplayShape.Circle);
            this._markFloodedCell = new DOEntity(Color.Blue, DisplayShape.Square);

            this._waterTable = new DOEntity(Color.Blue, DisplayShape.Line);
            this._horizFlowBarrier = new DOEntity(Color.Sienna, DisplayShape.Line);
        }

        /// <summary>
        /// 绘制指定的图形
        /// </summary>
        /// <param name="size"></param>
        /// <param name="color"></param>
        /// <param name="display"></param>
        /// <returns></returns>
       public object GetStyle(int size, System.Windows.Media.Color color, DisplayShape display)
       {
           if (display == DisplayShape.Circle)
           {
               Ellipse ell = new Ellipse();
               ell.Fill = new System.Windows.Media. SolidColorBrush(color);
               ell.Width = size;
               ell.Height = size;
               return ell;
           }
           if (display == DisplayShape.Square)
           {
               System.Windows.Shapes.Rectangle rec = new System.Windows.Shapes.Rectangle();
               rec.Fill = new System.Windows.Media.SolidColorBrush(color);
               rec.Width = size;
               rec.Height = size;
               return rec;
           }
           if (display == DisplayShape.Diamond)
           {
               System.Windows.Shapes.Rectangle rec = new System.Windows.Shapes.Rectangle();
               rec.Fill = new System.Windows.Media.SolidColorBrush(color);
               rec.Width = size;
               rec.Height = size;
               rec.RenderTransform = new System.Windows.Media.RotateTransform(45, size / 2, size / 2);
               return rec;
           }

           if (display == DisplayShape.TriangleUp)
           {

               Polygon pol = new Polygon();
               pol.Fill = new System.Windows.Media.SolidColorBrush(color);
               pol.Width = size;
               pol.Height = size;
               List<System.Windows.Point> arry = new List<System.Windows.Point>();
               arry.Add(new System.Windows.Point(size, 0));
               arry.Add(new System.Windows.Point(size / 2, size));
               arry.Add(new System.Windows.Point(0, 0));
               pol.Points = new System.Windows.Media.PointCollection(arry);
               pol.RenderTransform = new System.Windows.Media.RotateTransform(180, size / 2, size / 2);
               return pol;
           }

           //if (display == DisplayShape.Cross)
           //{
           //    Canvas canvas = new Canvas();
           //    canvas.Width = size;
           //    canvas.Height = size;
           //    Path path = new Path();
           //    System.Windows.Media.GeometryConverter gc = new System.Windows.Media.GeometryConverter();
           //    //"M0,0 L14,0"
           //    string str = "M0,0 L" + size + ",0";

           //    path.Data = (System.Windows.Media.Geometry)gc.ConvertFromString(str);
           //    path.Margin = new Thickness(0, size / 2, 0, 0);
           //    path.Stroke = new System.Windows.Media.SolidColorBrush(color);
           //    path.StrokeThickness = 2;
           //    canvas.Children.Add(path);

           //    path = new Path();
           //    gc = new System.Windows.Media.GeometryConverter();
           //    str = "M0,0 L0," + size;
           //    path.Data = (System.Windows.Media.Geometry)gc.ConvertFromString(str);
           //    path.Margin = new Thickness(size / 2, 0, 0, 0);
           //    path.Stroke = new System.Windows.Media.SolidColorBrush(color);
           //    path.StrokeThickness = 2;
           //    canvas.Children.Add(path);
           //    return canvas;
           //}
           //if (display == DisplayShape.CircleNoFill)
           //{
           //    Ellipse ell = new Ellipse();
           //    ell.Stroke = new System.Windows.Media.SolidColorBrush(color);
           //    ell.StrokeThickness = 2;
           //    ell.Width = size;
           //    ell.Height = size;
           //    return ell;
           //}

           //if (display == DisplayShape.SquareNoFill)
           //{
           //    System.Windows.Shapes.Rectangle rec = new System.Windows.Shapes.Rectangle();
           //    rec.Stroke = new System.Windows.Media.SolidColorBrush(color);
           //    rec.StrokeThickness = 2;
           //    rec.Width = size;
           //    rec.Height = size;
           //    return rec;
           //}

           //if (display == DisplayShape.DiamondNoFill)
           //{
           //    System.Windows.Shapes.Rectangle rec = new System.Windows.Shapes.Rectangle();
           //    rec.StrokeThickness = 2;
           //    rec.Stroke = new System.Windows.Media.SolidColorBrush(color);
           //    rec.Width = size;
           //    rec.Height = size;
           //    rec.RenderTransform = new System.Windows.Media.RotateTransform(45, size / 2, size / 2);
           //    return rec;
           //}

           //if (display == DisplayShape.TriangleNoFill)
           //{
           //    Polygon pol = new Polygon();
           //    pol.Stroke = new System.Windows.Media.SolidColorBrush(color);
           //    pol.StrokeThickness = 2;
           //    pol.Width = size;
           //    pol.Height = size;
           //    List<System.Windows.Point> arry = new List<System.Windows.Point>();
           //    arry.Add(new System.Windows.Point(size, 0));
           //    arry.Add(new System.Windows.Point(size / 2, size));
           //    arry.Add(new System.Windows.Point(0, 0));
           //    pol.Points = new System.Windows.Media.PointCollection(arry);
           //    pol.RenderTransform = new System.Windows.Media.RotateTransform(180, size / 2, size / 2);
           //    return pol;
           //}
           //if (display == DisplayShape.SlashCross)
           //{
           //    Canvas canvas = new Canvas();
           //    canvas.Width = size;
           //    canvas.Height = size;
           //    Path path = new Path();
           //    System.Windows.Media.GeometryConverter gc = new System.Windows.Media.GeometryConverter();
           //    //"M0,0 L14,0"
           //    string str = "M" + size + ",0" + " L0," + size;

           //    path.Data = (System.Windows.Media.Geometry)gc.ConvertFromString(str);
           //    //path.Margin = new Thickness(0, size / 2, 0, 0);
           //    path.Stroke = new System.Windows.Media.SolidColorBrush(color);
           //    path.StrokeThickness = 2;
           //    canvas.Children.Add(path);

           //    path = new Path();
           //    gc = new System.Windows.Media.GeometryConverter();
           //    str = "M" + size * 2 + "," + size + " L" + size + ",0";
           //    path.Data = (System.Windows.Media.Geometry)gc.ConvertFromString(str);
           //    path.Margin = new Thickness(-size, 0, 0, 0);

           //    path.Stroke = new System.Windows.Media.SolidColorBrush(color);
           //    path.StrokeThickness = 2;
           //    canvas.Children.Add(path);
           //    return canvas;
           //}
           if (display == DisplayShape.DottedLine)
           {
                
               Line line = new Line();
               line.X1 = 0;
               line.X2 = 14;
               line.Y1 = 0;
               line.Y2 = 0;
               line.Stroke = new System.Windows.Media.SolidColorBrush(color);
               System.Windows.Media.DoubleCollection doub = new System.Windows.Media.DoubleCollection();
               doub.Add(2);
               doub.Add(1);
               line.StrokeDashArray = doub;
               line.StrokeThickness = size;
               return line;
           }
           if (display == DisplayShape.Line)
           {
               
               Line line = new Line();
               line.X1 = 0;
               line.X2 = 20;
               line.Y1 = 0;
               line.Y2 = 0;           
               
               line.Stroke = new System.Windows.Media.SolidColorBrush(color);             
               line.StrokeThickness = size;
               return line;
           }
           return null;
       }


       #endregion


       //[field: NonSerialized]
       // public event EventHandler<DisplayOptionsChangedEventArgs> DisplayOptionsChanged;

       // public void AskDisplayOptionsGrid3dChanged()
       // {
       //     if (this.DisplayOptionsChanged != null)
       //     {
       //         this.DisplayOptionsChanged(this, new DisplayOptionsChangedEventArgs(this, DisplayOptionsType.ModFlow ));
       //     }           
       // }


        DOEntity _wells;

        public DOEntity Wells
        {
            get { return _wells; }
            set { _wells = value; }
        }

        DOEntity _rivers;

        public DOEntity Rivers
        {
            get { return _rivers; }
            set { _rivers = value; }
        }

        DOEntity _drains;

        public DOEntity Drains
        {
            get { return _drains; }
            set { _drains = value; }
        }

        DOEntity _generalHead;

        public DOEntity GeneralHead
        {
            get { return _generalHead; }
            set { _generalHead = value; }
        }

        DOEntity _constantHead;

        public DOEntity ConstantHead
        {
            get { return _constantHead; }
            set { _constantHead = value; }
        }

        DOEntity _transientData;

        public DOEntity TransientData
        {
            get { return _transientData; }
            set { _transientData = value; }
        }

        DOEntity _horizFlowBarrier;

        public DOEntity HorizFlowBarrier
        {
            get { return _horizFlowBarrier; }
            set { _horizFlowBarrier = value; }
        }

        DOEntity _dryCell;

        public DOEntity DryCell
        {
            get { return _dryCell; }
            set { _dryCell = value; }
        }

        DOEntity _waterTable;

        public DOEntity WaterTable
        {
            get { return _waterTable; }
            set { _waterTable = value; }
        }

        DOEntity _markFloodedCell;

        public DOEntity MarkFloodedCell
        {
            get { return _markFloodedCell; }
            set { _markFloodedCell = value; }
        }

        public object Clone()
        {
            DOModFlow obj = new DOModFlow();
            obj.ConstantHead =(DOEntity ) this.ConstantHead.Clone();
            obj.Drains = (DOEntity)this.Drains.Clone();
            obj.DryCell = (DOEntity)this.DryCell.Clone();
            obj.GeneralHead = (DOEntity)this.GeneralHead.Clone();
            obj.HorizFlowBarrier = (DOEntity)this.HorizFlowBarrier.Clone();
            obj.MarkFloodedCell = (DOEntity)this.MarkFloodedCell.Clone();
            obj.Rivers = (DOEntity)this.Rivers.Clone();
            obj.TransientData = (DOEntity)this.TransientData.Clone();
            obj.WaterTable = (DOEntity)this.WaterTable.Clone();
            obj.Wells = (DOEntity)this.Wells.Clone();
            return obj;
        }
        public List<string> ResetDOModflow(DOModFlow nModflow)
        {
            List<string> props = new List<string>();
            if (this._markFloodedCell!=nModflow.MarkFloodedCell)
            {
                this._markFloodedCell = nModflow.MarkFloodedCell;
                props.Add("MarkFloodedCell");                
            }
            if (this._constantHead != nModflow.ConstantHead)
            {
                this._constantHead = nModflow.ConstantHead;
                props.Add("ConstantHead");
            }
            if (this.Drains != nModflow.Drains)
            {
                this.Drains = nModflow.Drains;
                props.Add("Drains");
            }
            if (this.DryCell != nModflow.DryCell)
            {
                this.DryCell = nModflow.DryCell;
                props.Add("DryCell");
            }
            if (this.GeneralHead != nModflow.GeneralHead)
            {
                this.GeneralHead = nModflow.GeneralHead;
                props.Add("GeneralHead");
            }
            if (this.HorizFlowBarrier != nModflow.HorizFlowBarrier)
            {
                this.HorizFlowBarrier = nModflow.HorizFlowBarrier;
                props.Add("HorizFlowBarrier");
            }
            if (this.Rivers != nModflow.Rivers)
            {
                this.Rivers = nModflow.Rivers;
                props.Add("Rivers");
            }
            if (this.TransientData != nModflow.TransientData)
            {
                this.TransientData = nModflow.TransientData;
                props.Add("TransientData");
            }
            if (this.WaterTable != nModflow.WaterTable)
            {
                this.WaterTable = nModflow.WaterTable;
                props.Add("WaterTable");

            }
            if (this.Wells != nModflow.Wells)
            {
                this.Wells = nModflow.Wells;
                props.Add("Wells");
            }
           
            return props;
        }


    }
}
